﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;
using System.Web.Hosting;
using System.Xml;

namespace WeiSha.Core
{
	// Token: 0x02000020 RID: 32
	public class IDCardNumber
	{
		// Token: 0x17000054 RID: 84
		// (get) Token: 0x060000EA RID: 234 RVA: 0x0000767C File Offset: 0x0000587C
		// (set) Token: 0x060000EB RID: 235 RVA: 0x00007694 File Offset: 0x00005894
		public string Province
		{
			get
			{
				return this._province;
			}
			set
			{
				this._province = value;
			}
		}

		// Token: 0x17000055 RID: 85
		// (get) Token: 0x060000EC RID: 236 RVA: 0x000076A0 File Offset: 0x000058A0
		// (set) Token: 0x060000ED RID: 237 RVA: 0x000076B8 File Offset: 0x000058B8
		public string Area
		{
			get
			{
				return this._area;
			}
			set
			{
				this._area = value;
			}
		}

		// Token: 0x17000056 RID: 86
		// (get) Token: 0x060000EE RID: 238 RVA: 0x000076C4 File Offset: 0x000058C4
		// (set) Token: 0x060000EF RID: 239 RVA: 0x000076DC File Offset: 0x000058DC
		public string City
		{
			get
			{
				return this._city;
			}
			set
			{
				this._city = value;
			}
		}

		// Token: 0x17000057 RID: 87
		// (get) Token: 0x060000F0 RID: 240 RVA: 0x000076E8 File Offset: 0x000058E8
		// (set) Token: 0x060000F1 RID: 241 RVA: 0x00007700 File Offset: 0x00005900
		public DateTime Birthday
		{
			get
			{
				return this._birthday;
			}
			set
			{
				this._birthday = value;
			}
		}

		// Token: 0x17000058 RID: 88
		// (get) Token: 0x060000F2 RID: 242 RVA: 0x0000770C File Offset: 0x0000590C
		public int Age
		{
			get
			{
				return DateTime.Now.Year - this.Birthday.Year;
			}
		}

		// Token: 0x17000059 RID: 89
		// (get) Token: 0x060000F3 RID: 243 RVA: 0x0000773C File Offset: 0x0000593C
		// (set) Token: 0x060000F4 RID: 244 RVA: 0x00007754 File Offset: 0x00005954
		public short Sex
		{
			get
			{
				return this._sex;
			}
			set
			{
				this._sex = value;
			}
		}

		// Token: 0x1700005A RID: 90
		// (get) Token: 0x060000F5 RID: 245 RVA: 0x00007760 File Offset: 0x00005960
		// (set) Token: 0x060000F6 RID: 246 RVA: 0x00007778 File Offset: 0x00005978
		public string CardNumber
		{
			get
			{
				return this._cardnumber;
			}
			set
			{
				this._cardnumber = value;
			}
		}

		// Token: 0x1700005B RID: 91
		// (get) Token: 0x060000F7 RID: 247 RVA: 0x00007784 File Offset: 0x00005984
		// (set) Token: 0x060000F8 RID: 248 RVA: 0x0000779C File Offset: 0x0000599C
		public string Json
		{
			get
			{
				return this._json;
			}
			set
			{
				this._json = value;
			}
		}

		// Token: 0x060000F9 RID: 249 RVA: 0x000077A8 File Offset: 0x000059A8
		private static void FillAreas()
		{
			string text = HostingEnvironment.MapPath("~/Utilities/AreaCodeInfo.xml");
			bool flag = !File.Exists(text);
			if (!flag)
			{
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.Load(text);
				XmlNodeList elementsByTagName = xmlDocument.GetElementsByTagName("area");
				foreach (object obj in elementsByTagName)
				{
					XmlNode xmlNode = (XmlNode)obj;
					int num;
					int.TryParse(xmlNode.Attributes["code"].Value, out num);
					bool flag2 = num == 0;
					if (!flag2)
					{
						string value = xmlNode.Attributes["name"].Value;
						IDCardNumber.Areas.Add(num, value);
					}
				}
			}
		}

		// Token: 0x060000FA RID: 250 RVA: 0x0000788C File Offset: 0x00005A8C
		public static string GetArea(int code)
		{
			bool flag = IDCardNumber.Areas.Count < 1;
			if (flag)
			{
				IDCardNumber.FillAreas();
			}
			while (code.ToString().Length < 6)
			{
				code *= 10;
			}
			while (code.ToString().Length > 6)
			{
				code /= 10;
			}
			foreach (KeyValuePair<int, string> keyValuePair in IDCardNumber.Areas)
			{
				bool flag2 = keyValuePair.Key == code;
				if (flag2)
				{
					return keyValuePair.Value;
				}
			}
			return string.Empty;
		}

		// Token: 0x060000FB RID: 251 RVA: 0x00007950 File Offset: 0x00005B50
		public static string GetArea(string code)
		{
			bool flag = string.IsNullOrWhiteSpace(code);
			string text;
			if (flag)
			{
				text = string.Empty;
			}
			else
			{
				bool flag2 = code.Length > 6;
				if (flag2)
				{
					code = code.Substring(0, 6);
				}
				int num;
				int.TryParse(code, out num);
				string text2 = LBS.GetArea(num);
				bool flag3 = string.IsNullOrEmpty(text2);
				if (flag3)
				{
					text2 = IDCardNumber.GetArea(num);
				}
				text = text2;
			}
			return text;
		}

		// Token: 0x060000FC RID: 252 RVA: 0x000079B4 File Offset: 0x00005BB4
		public static IDCardNumber Get(string idCardNumber)
		{
			bool flag = IDCardNumber.Areas.Count < 1;
			if (flag)
			{
				IDCardNumber.FillAreas();
			}
			bool flag2 = !IDCardNumber.CheckIDCardNumber(idCardNumber);
			if (flag2)
			{
				throw new Exception("非法的身份证号码");
			}
			return new IDCardNumber(idCardNumber);
		}

		// Token: 0x060000FD RID: 253 RVA: 0x00007A00 File Offset: 0x00005C00
		public static bool CheckIDCardNumber(string idCardNumber)
		{
			bool flag = string.IsNullOrWhiteSpace(idCardNumber);
			bool flag2;
			if (flag)
			{
				flag2 = false;
			}
			else
			{
				idCardNumber = idCardNumber.Replace(" ", "");
				idCardNumber = idCardNumber.ToUpper();
				Regex regex = new Regex("^\\d{17}(\\d|X)$");
				Match match = regex.Match(idCardNumber);
				bool flag3 = !match.Success;
				if (flag3)
				{
					flag2 = false;
				}
				else
				{
					string text = idCardNumber.Substring(17, 1);
					double num = 0.0;
					for (int i = 2; i <= 18; i++)
					{
						num += (double)int.Parse(idCardNumber[18 - i].ToString(), NumberStyles.HexNumber) * (Math.Pow(2.0, (double)(i - 1)) % 11.0);
					}
					string[] array = new string[]
					{
						"1", "0", "X", "9", "8", "7", "6", "5", "4", "3",
						"2"
					};
					string text2 = array[(int)num % 11];
					bool flag4 = text2 != text;
					flag2 = !flag4;
				}
			}
			return flag2;
		}

		// Token: 0x060000FE RID: 254 RVA: 0x00007B60 File Offset: 0x00005D60
		public static IDCardNumber Radom()
		{
			long ticks = DateTime.Now.Ticks;
			return new IDCardNumber(IDCardNumber._radomCardNumber((int)ticks));
		}

		// Token: 0x060000FF RID: 255 RVA: 0x00007B8C File Offset: 0x00005D8C
		public static List<IDCardNumber> Radom(int count)
		{
			List<IDCardNumber> list = new List<IDCardNumber>();
			for (int i = 0; i < count; i++)
			{
				bool flag;
				string text;
				do
				{
					flag = false;
					int num = (int)DateTime.Now.Ticks;
					text = IDCardNumber._radomCardNumber(num * (i + 1));
					foreach (IDCardNumber idcardNumber in list)
					{
						bool flag2 = idcardNumber.CardNumber == text;
						if (flag2)
						{
							flag = true;
							break;
						}
					}
				}
				while (flag);
				list.Add(new IDCardNumber(text));
			}
			return list;
		}

		// Token: 0x06000100 RID: 256 RVA: 0x00007C50 File Offset: 0x00005E50
		private static string _radomCardNumber(int seed)
		{
			bool flag = IDCardNumber.Areas.Count < 1;
			if (flag)
			{
				IDCardNumber.FillAreas();
			}
			Random random = new Random(seed);
			string text;
			do
			{
				text = IDCardNumber.Areas[random.Next(0, IDCardNumber.Areas.Count - 1)];
			}
			while (text.Substring(4, 2) == "00");
			DateTime dateTime = DateTime.Now.AddYears(-random.Next(16, 60)).AddMonths(-random.Next(0, 12)).AddDays((double)(-(double)random.Next(0, 31)));
			string text2 = random.Next(1000, 9999).ToString("####");
			string text3 = text + dateTime.ToString("yyyyMMdd") + text2;
			double num = 0.0;
			for (int i = 2; i <= 18; i++)
			{
				num += (double)int.Parse(text3[18 - i].ToString(), NumberStyles.HexNumber) * (Math.Pow(2.0, (double)(i - 1)) % 11.0);
			}
			string[] array = new string[]
			{
				"1", "0", "X", "9", "8", "7", "6", "5", "4", "3",
				"2"
			};
			string text4 = array[(int)num % 11];
			return text3.Substring(0, 17) + text4;
		}

		// Token: 0x06000101 RID: 257 RVA: 0x00007E24 File Offset: 0x00006024
		private IDCardNumber(string idCardNumber)
		{
			this._cardnumber = idCardNumber;
			this._analysis();
		}

		// Token: 0x06000102 RID: 258 RVA: 0x00007E3C File Offset: 0x0000603C
		private void _analysis()
		{
			this._province = IDCardNumber.GetArea(this._cardnumber.Substring(0, 2));
			this._area = IDCardNumber.GetArea(this._cardnumber.Substring(0, 4));
			this._city = IDCardNumber.GetArea(this._cardnumber.Substring(0, 6));
			string text = this._cardnumber.Substring(6, 8);
			try
			{
				int num = (int)Convert.ToInt16(text.Substring(0, 4));
				int num2 = (int)Convert.ToInt16(text.Substring(4, 2));
				int num3 = (int)Convert.ToInt16(text.Substring(6, 2));
				this._birthday = new DateTime(num, num2, num3);
			}
			catch
			{
				throw new Exception("非法的出生日期");
			}
			string text2 = this._cardnumber.Substring(14, 3);
			this._sex = (short)((Convert.ToInt16(text2) % 2 == 0) ? 2 : 1);
			this._json = "prov:'{0}',area:'{1}',city:'{2}',year:{3},month:{4},day:{5},sex:{6},number:'{7}'";
			this._json = string.Format(this._json, new object[]
			{
				this._province,
				this._area,
				this._city,
				this._birthday.Year,
				this._birthday.Month,
				this._birthday.Day,
				this._sex,
				this._cardnumber
			});
			this._json = "{" + this._json + "}";
		}

		// Token: 0x04000049 RID: 73
		private string _province;

		// Token: 0x0400004A RID: 74
		private string _area;

		// Token: 0x0400004B RID: 75
		private string _city;

		// Token: 0x0400004C RID: 76
		private DateTime _birthday;

		// Token: 0x0400004D RID: 77
		private short _sex;

		// Token: 0x0400004E RID: 78
		private string _cardnumber;

		// Token: 0x0400004F RID: 79
		private string _json;

		// Token: 0x04000050 RID: 80
		private static readonly Dictionary<int, string> Areas = new Dictionary<int, string>();
	}
}
